package com.yesep.learn.netty.tcp.protocol;

import java.util.List;
import java.util.regex.Pattern;

import com.yesep.learn.netty.tcp.protocol.util.CommandUtil;

import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;

/**
 * @Description: 
 */
public class Test {
	public static void main(String[] args) throws Exception {
		//		String cmdStr1 = "QN=20160801085857223;ST=21;CN=2011;PW=123456;MN=A110000_0001;Flag=9;CP=&&DataTime=20160801085800;w01001-Rtd=63.0,w01001-Flag=N;w01003-Rtd=63.0,w01003-Flag=N;w01009-Rtd=63.0,w01009-Flag=N;w01010-Rtd=63.0,w01010-Flag=N;&&";
		//		String cmdStr2 = "QN=20160801085857223;ST=21;CN=2011;PW=123456;MN=A110000_0001;Flag=9;PNUM=5;PNO=2;CP=&&DataTime=20160801085800;w01001-Rtd=63.0,w01001-Flag=N;w01003-Rtd=63.0,w01003-Flag=N;w01009-Rtd=63.0,w01009-Flag=N;w01010-Rtd=63.0,w01010-Flag=N;&&";
		//		Command cmd1 = new Cmd2011(cmdStr1);
		//		System.out.println(cmd1);
		//		Command cmd2 = new Cmd2011(cmdStr2);
		//		System.out.println(cmd2);
		//
		//		Command cmd3 = new Cmd2011();
		//		cmd3.setCN("2222");
		//		cmd3.getCP().addData("w01001", "Rtd", "123");
		//		cmd3.getCP().addData("w01001", "Flag", "N");
		//		cmd3.getCP().addParam("DataTime", "20160801085800");
		//		System.out.println(cmd3);

		//		String msg1 = "QN=20160801085857223;ST=32;CN=1062;PW=100000;MN=010000A8900016F000169DC0;Flag=5;CP=&&RtdInterval=30&&";
		//		Command cmd1 = new Command(msg1);
		//		cmd1.getCP().addData("w01001", "Rtd", "123");
		//		cmd1.getCP().addData("w01001", "Flag", "N");
		//		cmd1.getCP().addData("w01002", "Rtd", "123");
		//		cmd1.getCP().addData("w01002", "Flag", "N");
		//		cmd1.getCP().addParam("DataTime", "20160801085800");
		//		System.out.println(cmd1);
		//
		//		System.out.println(StrUtil.padPre(Integer.toBinaryString(8), 8, "0"));
		//		System.out.println(StrUtil.padPre(Integer.toBinaryString(9), 8, "0"));
		//		System.out.println(StrUtil.padPre(Integer.toBinaryString(255), 8, "0"));
		Pattern CMD_PATTERN = Pattern.compile("^QN=(\\d*);ST=(\\d{2});CN=(.{4});PW=(.+);MN=(.+);Flag=(\\d{1,3});(PNUM=(\\d*);)?(PNO=(\\d*);)?CP=&&(.*)&&");

		String c2011_data = "QN=20190723161030000;ST=21;CN=2011;PW=123456;MN=09252062500001;Flag=5;PNUM=2;PNO=2;CP=&&DataTime=20190723161030;w01001-Rtd=0.000,w01001-Flag=N;w01003-Rtd=0.000,w01003-Flag=N;w01009-Rtd=0.000,w01009-Flag=N;w01010-Rtd=0.000,w01010-Flag=N;w01014-Rtd=0.000,w01014-Flag=N;w01019-Rtd=1.630,w01019-Flag=N;w21003-Rtd=0.066,w21003-Flag=N;w21001-Rtd=0.040,w21001-Flag=N;w21011-Rtd=0.022,w21011-Flag=N;w01016-Rtd=84.090,w01016-Flag=N;w01022-Rtd=0.000,w01022-Flag=N;w22001-Rtd=0.000,w22001-Flag=N&&";

		String c2011 = "##" + StrUtil.padPre(String.valueOf(c2011_data.length()), 4, "0") + c2011_data + CommandUtil.CRC16(c2011_data);
		List<String> rs = ReUtil.getAllGroups(CommandUtil.CMD_PATTERN, c2011_data, false);
		System.out.println(rs);
		System.out.println(c2011);
	}
}
